#include <stdio.h>

/*
 * 函数指针作为回调函数
 */
int add(int a, int b)
{
	return a + b;
}
int sub(int a, int b)
{
	return a - b;
}

int calc(int a, int b, int (*pfn)(int, int))
{
	return pfn(a, b);
}

/*
 * 函数指针作为结构体的成员变量
 */
typedef struct _shape{
	char* name;
	void (*draw)(struct _shape *);
} SHAPE;

void draw_cicle(SHAPE *shape)
{
	printf("My name is %s, I like drawing a circle!\n", shape->name);
}
void draw_line(SHAPE *shape)
{
	printf("My name is %s, I like drawing a line!\n", shape->name);
}
int update(SHAPE *shape)
{
	shape->draw(shape);
}
